Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax: Make parsing of paths whitespace agnostic + some other changes #33041

Merged
merged 10 commits into from
Apr 24, 2016

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Apr 16, 2016

Paths are mostly parsed without taking whitespaces into account, e.g. std :: vec :: Vec :: new () parses successfully, however, there are some special cases involving keywords super, self and Self. For example, self:: is considered a path start only if there are no spaces between self and ::. These restrictions probably made sense when self and friends weren't keywords, but now they are unnecessary.

The first two commits remove this special treatment of whitespaces by removing token::IdentStyle entirely and therefore fix #14109.
This change also affects naked self and super (which are not tightly followed by ::, obviously) they can now be parsed as paths, however they are still not resolved correctly in imports (cc @jseyfried, see compile-fail/use-keyword.rs), so #29036 is not completely fixed.

The third commit also makes super, self, Self and static keywords nominally (before this they acted as keywords for all purposes) and removes most of remaining "special idents".

The last commit (before tests) contains some small improvements - some qualified paths with type parameters are parsed correctly, parse_path is not used for parsing single identifiers, imports are sanity checked for absence of type parameters - such type parameters can be generated by syntax extensions or by macros when #10415 is fixed (~~soon!~~already!).

This patch changes some pretty basic things in libsyntax, like token::Token and the keyword list, so it's a plugin-[breaking-change].

r? @eddyb

(2, __Unused2, "<__unused2>");
(3, __Unused3, "<__unused3>");
(4, __Unused4, "<__unused4>");
(5, __Unused5, "<__unused5>");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove all of these? And replace special_idents with "non-strict keywords"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just wanted to leave some free space so the diff is not messed up on every new contextual keyword, but it's not so important I suppose.
Also, naming is hard, what is the short and obvious name to use instead of special_idents? weak_keywords maybe? Also, "" doesn't even look like a keyword!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I wouldn't even have a name. I'd just put all of them in the same bag, and just auto-generate the STRICT_KEYWORD_{START,END} from the list, with 'strict still there.

@bors
Copy link
Contributor

bors commented Apr 17, 2016

☔ The latest upstream changes (presumably #32875) made this pull request unmergeable. Please resolve the merge conflicts.

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 17, 2016
syntax: Parse import prefixes as paths

Fixes rust-lang#10415

r? @eddyb
(This partially intersects with rust-lang#33041)
@petrochenkov
Copy link
Contributor Author

@eddyb
I've updated the PR.
Keywords and special idents are merged together and the keyword generating macro is simplified.
The "bounds" for strict/reserved keywords are written manually now, but I'd say it's less error prone than the previous macro shenanigans.
The second commit contains some other small changes, see the commit message for description.

@eddyb
Copy link
Member

eddyb commented Apr 18, 2016

LGTM, very nice! @nrc @erickt @Manishearth, any objections?

@nrc
Copy link
Member

nrc commented Apr 18, 2016

Should be breaking-batch, rather than being landed directly. But I think we should try to land it soon so it doesn't rot. cc @Manishearth

@nrc
Copy link
Member

nrc commented Apr 18, 2016

LGTM

@Manishearth
Copy link
Member

We don't have any other breaking-batch changes queued up, but this is large enough that it can be landed directly. Let's wait a few days for the stakeholders to prepare for this, and land it then.

(In the meantime, if you have any breaking changes planned, now is the time to make PRs!)

@Manishearth
Copy link
Member

Left a comment on #31645, feel free to land in a few days

@Manishearth
Copy link
Member

Please land this simultaneously with #31414 . I'll do it myself in a day or two if both get approved.

@petrochenkov
Copy link
Contributor Author

petrochenkov commented Apr 20, 2016

I've pushed one more commit.
It makes is_path_start precise and fixes some error message regressions caused by that.

@Manishearth
Copy link
Member

Is this ready to land? (two LGTMs, seems good) Just mention r=me, don't actually tell bors to approve it.

@nrc
Copy link
Member

nrc commented Apr 21, 2016

@Manishearth r=me

Lift some restrictions on type parameters in paths
Sanity check import paths for type parameters
Simplify the macro used for generation of keywords
Make `Keyword::ident` private
syntax: Merge PathParsingMode::NoTypesAllowed and PathParsingMode::ImportPrefix
syntax: Rename PathParsingMode and its variants to better express their purpose
syntax: Remove obsolete error message about 'self lifetime
syntax: Remove ALLOW_MODULE_PATHS workaround
syntax/resolve: Adjust some error messages
resolve: Compare unhygienic (not renamed) names with keywords::Invalid, invalid identifiers may appear to be valid after renaming
@petrochenkov
Copy link
Contributor Author

@Manishearth
I've rebased this PR, added #33157 to it and regenerated the failing keyword parsing tests.

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 24, 2016
 Paths are mostly parsed without taking whitespaces into account, e.g. `std :: vec :: Vec :: new ()` parses successfully, however, there are some special cases involving keywords `super`, `self` and `Self`. For example, `self::` is considered a path start only if there are no spaces between `self` and `::`. These restrictions probably made sense when `self` and friends weren't keywords, but now they are unnecessary.

The first two commits remove this special treatment of whitespaces by removing `token::IdentStyle` entirely and therefore fix rust-lang#14109.
This change also affects naked `self` and `super` (which are not tightly followed by `::`, obviously) they can now be parsed as paths, however they are still not resolved correctly in imports (cc @jseyfried, see `compile-fail/use-keyword.rs`), so rust-lang#29036 is not completely fixed.

The third commit also makes `super`, `self`, `Self` and `static` keywords nominally (before this they acted as keywords for all purposes) and removes most of remaining \"special idents\".

The last commit (before tests) contains some small improvements - some qualified paths with type parameters are parsed correctly, `parse_path` is not used for parsing single identifiers, imports are sanity checked for absence of type parameters - such type parameters can be generated by syntax extensions or by macros when rust-lang#10415 is fixed (~~soon!~~already!).

This patch changes some pretty basic things in `libsyntax`, like `token::Token` and the keyword list, so it's a plugin-[breaking-change].

r? @eddyb
bors added a commit that referenced this pull request Apr 24, 2016
Batch up breaking libsyntax changes

Contains:

 - #33125
 - #33041
 - #33157

cc #31645
@bors bors merged commit 4bd44be into rust-lang:master Apr 24, 2016
lambda-fairy added a commit to lambda-fairy/maud that referenced this pull request Apr 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use super :: A does not parse
5 participants